use shrid year_elec year_road year if year==2010 using "${replication}\data\for_event_elecXroad.dta", clear

drop year 
expand 13
bysort shrid: gen year=2002+_n

foreach inf in elec road {
	gen `inf'=(year_`inf'<=year)
}

global graph_options `" graphregion(color(white)) stack over(year) legend(rows(1) pos(6)) ytitle("Number of villages" " ")"'


preserve 


gen only_road=road*(1-elec)
gen only_elec=elec*(1-road)
gen both=elec*road

gcollapse (sum)   only* both, by(year)

graph bar  only_elec only_road both , $graph_options bar(1, color(ebblue)) bar(2, color(red))   bar(3, color(purple))  legend( label(1 "Electricity only" ) label(2 "Road only") label(3 "Both")) 

